<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>我的购物车</title>
    <link rel="stylesheet" href="css/shopping_cart.css"/>
    <link rel="stylesheet" href="css/shopping_cart2.css"/>
    <link rel="stylesheet" href="css/public.css"/>
    <link rel="stylesheet" href="css/footer.css"/>
    <link rel="stylesheet" type="text/css" href="css/help-center.css" />
    <!--<script type="text/javascript" src="js/shoppingcart.js" charset="GB2132"></script>-->
    <link rel="stylesheet" type="text/css" href="css/help-center.css" />

</head>
<body>
<script>
    window.onload = function() {
        var aData = [{
            "imgUrl": "img/03-car-01.png",
            "proName": " 小米手环4 NFC版 ",
            "proPrice": "229",
            "proComm": "1"
        },
            {
                "imgUrl": "img/03-car-02.png",
                "proName": " Redmi AirDots真无线蓝牙耳机 ",
                "proPrice": "99.9",
                "proComm": "9.7"
            },
            {
                "imgUrl": "img/03-car-03.png",
                "proName": " 米家蓝牙温湿度计 ",
                "proPrice": "65",
                "proComm": "1.3"
            },
            {
                "imgUrl": "img/03-car-04.png",
                "proName": " 小米小爱智能闹钟 ",
                "proPrice": "149",
                "proComm": "1.1"
            },
            {
                "imgUrl": "img/03-car-05.png",
                "proName": "米家电子温湿度计Pro  ",
                "proPrice": "750",
                "proComm": "0.3"
            },
            {
                "imgUrl": "img/03-car-06.png",
                "proName": " 小米手环3 NFC版 Pro  ",
                "proPrice": "199",
                "proComm": "3.3"
            },
            {
                "imgUrl": "img/03-car-07.png",
                "proName": " 小米手环3 / 4 通用腕带",
                "proPrice": "19.9",
                "proComm": "1.2"
            },
            {
                "imgUrl": "img/03-car-08.png",
                "proName": "  米家温湿度传感器 ",
                "proPrice": "45",
                "proComm": "0.6"
            },
            {
                "imgUrl": "img/03-car-09.png",
                "proName": "  米家电子温湿度计Pro 3个装  ",
                "proPrice": "207",
                "proComm": "0.3"
            },
            {
                "imgUrl": "img/03-car-10.png",
                "proName": " 小米手环3 ",
                "proPrice": "199",
                "proComm": "7.2"
            }
        ];
        var oBox = document.getElementById("box");
        var oCar = document.getElementById("car");
        var oUl = document.getElementsByTagName("ul")[0];

        for (var i = 0; i < aData.length; i++) {
            var oLi = document.createElement("li");
            var data = aData[i];

            oLi.innerHTML += '<div class="pro_img"><img src="' + data["imgUrl"] + '" width="150" height="150"></div>';
            oLi.innerHTML += '<h3 class="pro_name"><a href="#">' + data["proName"] + '</a></h3>';
            oLi.innerHTML += '<p class="pro_price">' + data["proPrice"] + '元</p>';
            oLi.innerHTML += '<p class="pro_rank">' + data["proComm"] + '万人好评</p>';
            oLi.innerHTML += '<div class="add_btn">加入购物车</div>';
            oUl.appendChild(oLi);

        }
        var aBtn = getClass(oBox, "add_btn");//获取box下的所有添加购物车按钮
        var number = 0;//初始化商品数量
        for (var i = 0; i < aBtn.length; i++) {
            number++;
            aBtn[i].index = i;
            aBtn[i].onclick = function() {
                var oDiv = document.createElement("div");
                var data = aData[this.index];
                oDiv.className = "row hid";
                oDiv.innerHTML += '<div class="check left"> <i class="i_check" id="i_check" onclick="i_check()" >√</i></div>';
                oDiv.innerHTML += '<div class="img left"><img src="' + data["imgUrl"] + '" width="80" height="80"></div>';
                oDiv.innerHTML += '<div class="name left"><span>' + data["proName"] + '</span></div>';
                oDiv.innerHTML += '<div class="price left"><span>' + data["proPrice"] + '元</span></div>';
                oDiv.innerHTML +=' <div class="item_count_i"><div class="num_count"><div class="count_d">-</div><div class="c_num">1</div><div class="count_i">+</div></div> </div>'
                oDiv.innerHTML += '<div class="subtotal left"><span>' + data["proPrice"] + '元</span></div>'
                oDiv.innerHTML += '<div class="ctrl left"><a href="javascript:;">×</a></div>';
                oCar.appendChild(oDiv);
                var flag = true;
                var check = oDiv.firstChild.getElementsByTagName("i")[0];
                check.onclick = function() {
                    // console.log(check.className);
                    if (check.className == "i_check i_acity") {
                        check.classList.remove("i_acity");

                    } else {
                        check.classList.add("i_acity");
                    }
                    getAmount();
                }
                var delBtn = oDiv.lastChild.getElementsByTagName("a")[0];
                delBtn.onclick = function() {
                    var result = confirm("确定删除吗?");
                    if (result) {
                        oCar.removeChild(oDiv);
                        number--;
                        getAmount();
                    }
                }
                var i_btn = document.getElementsByClassName("count_i");
                for (var k = 0; k < i_btn.length; k++) {
                    i_btn[k].onclick = function() {
                        bt = this;
                        //获取小计节点
                        at = this.parentElement.parentElement.nextElementSibling;
                        //获取单价节点
                        pt = this.parentElement.parentElement.previousElementSibling;
                        //获取数量值
                        node = bt.parentNode.childNodes[1];
                        console.log(node);
                        num = node.innerText;
                        num = parseInt(num);
                        num++;
                        node.innerText = num;
                        //获取单价
                        price = pt.innerText;
                        price = price.substring(0, price.length - 1);
                        //计算小计值
                        at.innerText = price * num + "元";
                        //计算总计值
                        getAmount();
                    }
                }
                //获取所有的数量减号按钮
                var d_btn = document.getElementsByClassName("count_d");
                for (k = 0; k < i_btn.length; k++) {
                    d_btn[k].onclick = function() {
                        bt = this;
                        //获取小计节点
                        at = this.parentElement.parentElement.nextElementSibling;
                        //获取单价节点
                        pt = this.parentElement.parentElement.previousElementSibling;
                        //获取c_num节点
                        node = bt.parentNode.childNodes[1];
                        num = node.innerText;
                        num = parseInt(num);
                        if (num > 1) {
                            num--;
                        }
                        node.innerText = num;
                        //获取单价
                        price = pt.innerText;
                        price = price.substring(0, price.length - 1);
                        //计算小计值
                        at.innerText = price * num + "元";
                        //计算总计值
                        getAmount();
                    }
                }

                delBtn.onclick = function() {
                    var result = confirm("确定删除吗?");
                    if (result) {
                        oCar.removeChild(oDiv);
                        number--;
                        getAmount();
                    }
                }

            }
        }

    }

    function getClass(oBox, tagname) {
        var aTag = oBox.getElementsByTagName("*");
        var aBox = [];
        for (var i = 0; i < aTag.length; i++) {
            if (aTag[i].className == tagname) {
                aBox.push(aTag[i]);
            }
        }
        return aBox;
    }


    var index = false;
    function checkAll() {
        var choose = document.getElementById("car").getElementsByTagName("i");
        // console.log(choose);
        if (choose.length != 1) {
            for (i = 1; i < choose.length; i++) {
                if (!index) {
                    choose[0].classList.add("i_acity2")
                    choose[i].classList.add("i_acity");
                } else {
                    choose[i].classList.remove("i_acity");
                    choose[0].classList.remove("i_acity2")
                }
            }
            index = !index;
        }
        getAmount();
    }

    //进行价格合计
    function getAmount() {
        // console.log(ys);
        ns = document.getElementsByClassName("i_acity");
        console.log(ns);
        sum = 0;
        //选中框
        document.getElementById("price_num").innerText = sum;
        for (y = 0; y < ns.length; y++) {
            //小计
            amount_info = ns[y].parentElement.parentElement.lastElementChild.previousElementSibling;
            num = parseInt(amount_info.innerText);
            sum += num;
            document.getElementById("price_num").innerText = sum;
        }
    }
</script>

<div class="wrap">
    <div class="header">
        <div class="container clearFloat">
            <div class="logo"><img src="img/logo-mi2.png" alt="" width="56" height="56"/></div>
            <div class="headerTitle">
                <h2>我的购物车</h2>
                <p>温馨提示：产品是否购买成功，最终以下单为准哦，请尽快结算</p>
            </div>
            <div class="userInfo">
                <a class="login" href="my.html">L.</a>
                <a class="register" href="">我的订单</a>
            </div>
        </div>
    </div>
    <div id="car" class="car">
        <div class="head_row hid">
            <div class="check left"> <i onclick="checkAll()">√</i></div>
            <div class="img left">&nbsp;&nbsp;全选</div>
            <div class="name left">商品名称</div>
            <div class="price left">单价</div>
            <div class="number left">数量</div>
            <div class="subtotal left">小计</div>
            <div class="ctrl left">操作</div>
        </div>
    </div>
    <div id="sum_area">
        <div id="pay">去结算</div>
        <div id="pay_amout">合计：<span id="price_num">0</span>元</div>
    </div>
    <div class="main2">
        <div id="box">
            <h2 class="box_head"><span>买购物车中商品的人还买了</span></h2>
            <ul>
            </ul>
        </div>
    </div>
    <div class="footer">
        <div class="footer-service">
            <ul>
                <li><a href=""><span class="iconfont">&#xe60f;</span>预约维修服务</a></li>
                <li><a href=""><span class="iconfont">&#xe622;</span>7天无理由退货</a></li>
                <li><a href=""><span class="iconfont">&#xe501;</span>15天免费换货</a></li>
                <li><a href=""><span class="iconfont">&#xe639;</span>满69包邮</a></li>
                <li><a href=""><span class="iconfont">&#xe612;</span>520余家售后网点</a></li>
            </ul>
        </div>
        <div class="footer-links">
            <dl>
                <dt>帮助中心</dt>
                <dd><a href="">账户管理</a></dd>
                <dd><a href="">购物指南</a></dd>
                <dd><a href="">订单操作</a></dd>
            </dl>
            <dl>
                <dt>服务支持</dt>
                <dd><a href="">售后政策</a></dd>
                <dd><a href="">自动服务</a></dd>
                <dd><a href="">相关下载</a></dd>
            </dl>
            <dl>
                <dt>线下门店</dt>
                <dd><a href="">小米之家</a></dd>
                <dd><a href="">服务网点</a></dd>
                <dd><a href="">授权体验店</a></dd>
            </dl>
            <dl>
                <dt>关于小米</dt>
                <dd><a href="">了解小米</a></dd>
                <dd><a href="">加入小米</a></dd>
                <dd><a href="">投资者关系</a></dd>
                <dd><a href="">企业社会责任</a></dd>
                <dd><a href="">廉洁举报</a></dd>
            </dl>
            <dl>
                <dt>关注我们</dt>
                <dd><a href="">新浪微博</a></dd>
                <dd><a href="">官方微信</a></dd>
                <dd><a href="">联系我们</a></dd>
                <dd><a href="">公益基金会</a></dd>
            </dl>
            <dl>
                <dt>特色服务</dt>
                <dd><a href="">F码通道</a></dd>
                <dd><a href="">礼物码</a></dd>
                <dd><a href="">防伪查询</a></dd>
            </dl>
            <div class="contact">
                <p class="phone">400-100-5678</p>
                <p>8:00-18:00(仅收市话费)</p>
                <a href="" class="kefu">人工客服</a>
                <div class="follow">
                    关注小米
                    <a href=""></a>
                    <a href=""></a>
                    <img src="imag/mi.png">
                </div>
            </div>
        </div>
        <div class="footer-info">
            <div class="container2">
                <img class="logo2" src="imag/logo-mi2.png"/>
                <div class="info-text">
                    <p>小米商城&nbsp;|&nbsp;MIUI&nbsp;|&nbsp;米家&nbsp;|&nbsp;米聊&nbsp;|&nbsp;多看&nbsp;|&nbsp;游戏&nbsp;|&nbsp;
                        政企服务&nbsp;|&nbsp;小米天猫店&nbsp;|&nbsp;小米集团隐私政策&nbsp;|&nbsp;小米公司儿童信息保护规则&nbsp;|&nbsp;
                        小米商城隐私政策&nbsp;|&nbsp;小米商城用户协议&nbsp;|&nbsp;问题反馈&nbsp;|&nbsp;Select Location</p>
                    <p>北京互联网法院法律服务工作站&nbsp;|&nbsp;中国消费者协会&nbsp;|&nbsp;北京市消费者协会</p>
                    <p>◎mi.com京ICP证110507号&nbsp;京ICP备10046444号&nbsp;京公网安备11010802020134号&nbsp;京网文[2020]0276-042号<br>
                        (京)网械平台备字(2018) 第00005号&nbsp;互联网药品信息服务资格证(京)-非经营性-2014-0090营业执照&nbsp;医疗器械质量公告<br>
                        增值电信业务许可证&nbsp;网络食品经营备案&nbsp;京食药网食备202010048&nbsp;食品经营许可证<br>
                        违法和不良信息举报电话: 171-5104-4404 知识产权侵权投诉&nbsp;本网站所列数据,除特殊说明，所有数据均出自我司实验室测试<br></p>
                </div>
                <div class="info-links">
                    <a class="nofollow" href=""></a>
                    <a class="nofollow" href=""></a>
                    <a class="nofollow" href=""></a>
                    <a class="nofollow" href=""></a>
                    <a class="nofollow" href=""></a>
                </div>
            </div>
            <div class="slogan"></div>
        </div>
    </div>

</div>
</body>
</html>